package com.zhaokuner.parentstarter.exception;


import com.zhaokuner.parentstarter.enumeration.SuperCodeMsg;
import com.zhaokuner.parentstarter.resultcode.ResultCode;
import com.zhaokuner.parentstarter.resultcode.SuperResultCodeUtil;

import java.util.HashMap;

/**
 * 类描述:业务异常
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/12/11 09:58
 */
public class BusinessException extends RuntimeException implements SuperCodeMsg {

    private static final long serialVersionUID = 595540462244810997L;
    /**
     * code码
     */
    private Integer code;
    /**
     * 说明描述
     */
    private String msg;
    /**
     * 数据
     */
    private Object data = new HashMap<String, Object>(1);

    public BusinessException() {
        super();
        code = SuperResultCodeUtil.FAILURE.getCode();
        msg = SuperResultCodeUtil.FAILURE.getMsg();
    }

    public BusinessException(SuperCodeMsg e) {
        super();
        code = e.getCode();
        msg = e.getMsg();
    }

    public BusinessException(String msg) {
        super();
        code = SuperResultCodeUtil.FAILURE.getCode();
        this.msg = msg;
    }


    public BusinessException(ResultCode rc, Throwable cause) {
        super(cause);
        code = rc.getCode();
        msg = rc.getMsg();
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
